function [bParams, oParams, setts]=model_settings(debt_case,pbar_in)
% Function that loads the other functions and base case settings

% Variables:
% debt_case		is 1 if no debt, 2 if static debt
% pbar_in       number of products

%% Model parameters

% Set pbar if its not given
    if nargin==1
        oParams.pbar = 80;
    else
        oParams.pbar = pbar_in;
    end

    oParams.r = 0.042;
    oParams.pi = 0.15;
    oParams.n = 2;
    oParams.alpha = 0.45;

	bParams.gamma = 2; 
	bParams.beta = 4.066; 
    bParams.H = 3.35/(1-oParams.pi); 
	bParams.xi = 0.0109; 
    bParams.theta = 0.125;
    bParams.theta_e = 0.125;
    bParams.eta = 0.973;
     
    oParams.n_e = 7;
    oParams.product_distribution_entrants = binopdf(0:oParams.n_e,oParams.n_e,bParams.theta_e);
    oParams.product_distribution_entrants = oParams.product_distribution_entrants(2:end);
    oParams.product_distribution_entrants(oParams.n_e+1:oParams.pbar)=0;
    oParams.product_distribution_entrants = oParams.product_distribution_entrants/sum(oParams.product_distribution_entrants);

%% Technical settings

% Initial equity and debt value
	setts.equity_in = (1-oParams.pi)*(0:oParams.pbar)/(oParams.r+0.1);
	setts.debt_in = ones(1,oParams.pbar+1)/oParams.r;

% Set options f^e optimizer
	setts.options = optimoptions('fmincon','Display','Off');
    
% Range f and max number of iterations
	setts.f_max = 2;
	setts.f_min = 0.0;
    setts.f_max_iterations = 20;

% Simulations
	setts.m = 40000;
    setts.dt = 0.04;
	setts.T = 17 + setts.dt;
	setts.T0 = 2;

% Grid lambda    
    setts.lambda_grid = (0:0.0075:15);
	setts.n_lambda = length(setts.lambda_grid);
	setts.lambda_max = max(setts.lambda_grid);
      
% Show lambda error    
    setts.lambda_error = 0;  	

% Entry subsidie ( * tax rate) with = 1 none  
    setts.EntrySubsidy = 0;
    
% Set precision
	setts.e_prec = 0.001;
	setts.d_prec = 0.001;
    setts.recovery_prec = 0.01;
    setts.f_prec = 0.001;

% Debt case and coupon vector used
	setts.nodebt = 0;
	setts.debt_static = 0;
	if debt_case==1
		setts.C = 0;
		setts.nodebt = 1;
	elseif debt_case==2
        setts.debt_static = 1;
        setts.C = (0:0.1:500)/50;
    end

% Add functions and file path
	fsep = filesep;
	setts.dir = strrep([pwd,'\results\'],'\',fsep);
	addpath(strrep(setts.dir,'results','functions model'));
	addpath(strrep(setts.dir,'results','functions results'));
	addpath(strrep(setts.dir,'results','functions other'));

end
